/*LICENSE_BEGIN
 * ******************************************************************
 * All original parts of SoccerScope2003 have copyright (2003) by
 * Team YowAI, represented by Mr. Shuhei Shiota
 * The Department of Creative Informatics
 * The Graduate School of Information Science and Technology
 * The University of Tokyo
 * 
 * Additional classes (except libraries in /lib) were developed by 
 * the Dainamite Robocup-Team of the DAI-Labor, TU-Berlin 
 * (www.dai-labor.de)
 * 
 * Extended/new classes/packages are:
 *   soccerscope.analyzer.LogfileAnalyzer
 *   soccerscope.daistatistic.*
 *   soccerscope.daistatistic.charts.*
 *   soccerscope.daistatistic.tools.*
 *   soccerscope.db.*
 *   soccerscope.dialog.*
 *   soccerscope.model.PlayerWorldModel
 *   soccerscope.model.SimplePlayer
 *   soccerscope.net.AgentConnector
 *   soccerscope.training.*
 *   soccerscope.training.conditions.*
 * ******************************************************************
LICENSE_END*/
package soccerscope.view.layer;

import java.awt.Graphics;

import soccerscope.model.ClientScene;
import soccerscope.model.Param;
import soccerscope.model.Player;
import soccerscope.util.Color2;
import soccerscope.view.FieldPane;

/**
 * draws an arrow to the player we heared
 * 
 */
public class HearLayer extends Layer {

	/**
	 * @param fieldPane
	 * @param enable
	 */
	public HearLayer(FieldPane fieldPane, boolean enable) {

		super(fieldPane, enable);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see soccerscope.view.layer.Layer#getLayerName()
	 */
	@Override
	public String getLayerName() {

		return "Hear";
	}

	@Override
	public void draw(Graphics g) {

		if (!this.enable)
			return;

		ClientScene clientScene = this.fieldPane.getScene();
		for (int i = 0; i < Param.MAX_PLAYER * 2; i++) {
			if (!clientScene.player[i].isEnable()
					|| !this.fieldPane.isSelected(i))
				continue;

			int mateNumber;
			Player p;
			Player mate;
			int index = -1;

			for (String s : clientScene.player[i].hearMessage) {
				if (s.length() == 0)
					continue;

				index = s.indexOf('-');
				if (index < 0)
					continue;

				mateNumber = Integer.parseInt(s.substring(0, index));
				if (mateNumber == 0)
					continue;
				p = clientScene.player[i];
				if (i > 10)
					mateNumber += 11;
				mate = clientScene.player[mateNumber - 1];
				g.setColor(Color2.red);
				this.drawArrow(g, p.pos, mate.pos);
			}
		}
	}

}
